<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>todolist</title>
    <script src="./vue.js"></script>
</head>
<body>
    <div id="app">
        <input type="text" v-model="message">
        <button v-on:click="handle">提交</button>
        <span>{{message}}</span>
        <ul>
            <!--<li v-for="item in lists">{{item}}</li>-->
            <liitem @delete="deletes" v-bind:content="item" v-bind:index="index" v-for="(item,index) in lists"></liitem>
            <liitem2 v-bind:content="item" v-for="item in lists"></liitem2>
        </ul>
    </div>
    <script>
        Vue.component('liitem',{
            props: ['content','index'],
            template:`<li @click="del">{{content}}</li>`,
            methods: {
                del: function(){
                    this.$emit("delete",this.index)
                }
            }
        })
        var vm = new Vue({
            el: '#app',
            data: {
                message: 'hello',
                lists: []
            },
            methods:{
                handle: function(){
                    this.lists.push(this.message);
                    this.message = '';
                },
                deletes: function(index){
                    this.lists.splice(index,1)
                }
            },
            components: {
                "liitem2": {
                    template: `<li>{{content}}</li>`,
                    props: ['content']
                }
            }

        })
    </script>
</body>
</html>